package cn.tradewin.common.realm;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.cache.MemoryConstrainedCacheManager;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.tapestry5.ioc.annotations.InjectService;

public class TwdRetryLimitSecurityRealm extends AuthorizingRealm {

	public static final String SECURITY_NAME = "TwdRetryLimitSecurity";
	
	
	public TwdRetryLimitSecurityRealm(@InjectService("RetryLimitHashedCredentialsMatcher")
	CredentialsMatcher retryLimitMatcher) {
		super();
		this.setName(SECURITY_NAME);
		this.setCredentialsMatcher(retryLimitMatcher);
		this.setCacheManager(new MemoryConstrainedCacheManager());
	}
	
	
	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(
			PrincipalCollection principals) {
		return null;
	}

	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(
			AuthenticationToken token) throws AuthenticationException {
		return new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), getName());
	}
}
